home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4009 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.bellglobal.com!stupy
  2. From: stupy@freenet.durham.org (Steve Tupy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Recursive function -> how do you exit one?
  5. Date: 30 Jan 1996 20:43:21 GMT
  6. Organization: Durham Free-Net
  7. Message-ID: <4elvt9$ood@news.bellglobal.com>
  8. References: <4eh1g8$aba@pulp.ucs.ualberta.ca> <310d27a6.171790522@news.demon.co.uk>
  9. NNTP-Posting-Host: 204.101.165.17
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. : You need to return a value which makes all the recursed functions exit
  13. : without further processing.
  14.  
  15. : if the function returns an int then you could return -1 as aborted.
  16. : if it returns a char or char* you can use a (first) character that
  17. : cannot exist in your string. eg 0xff
  18.  
  19. : char* foo()
  20. : {
  21. :    result=foo();
  22. :    if(*result!=0xff)
  23. :    {
  24. :       // process things here //
  25. :       if (aborted) return "\xff";
  26. :    }
  27. :    return result;
  28. : }
  29.  
  30. : Does that help?
  31.  
  32.     What is result, an int? Where is it defined? Don't you agree that it
  33. should also be static? If not, you might find that its value gets lost on
  34. the stack, especially when you are unwinding the stack during a recursive
  35. call...
  36.  
  37. Just asking ;)
  38.  
  39. Take care
  40.  
  41. --
  42. Steve
  43.